public class AccountCollection
{
    private Account[] collection;
    private int count, number = 0;

    public AccountCollection()
    {
        collection = new Account[30];
        count = 0;
    }

    public void AddAccount(String name, long acctNumber, double balance)
    {
        collection[count] = new Account(name, acctNumber, balance);
        count++;
    }

    public String setSave(double savemoney, int number)
    {
        double balance;
        if (number < 0 && number > 30)
            return "错误，该账户不在管理范围";
        else
            collection[number].deposit(savemoney);
        balance = collection[number].getBalance();

        return "你给第" + (1 + number) + "位账户存了" + savemoney +
                "该账户剩余额度：" + balance;
    }

    public String setDraw(double getmoney, int number, double fee) {
        if (number < 0 && number > 30)
            return "错误，该账户不在管理范围.";
        else if (getmoney > collection[number].getBalance())
            return "错误，第"+(number+1)+"用户您的余额已不足.";
        else
            collection[number].withdraw(getmoney, fee);

        return "您从第" + (1 + number) + "位账户取出" + getmoney +
                "该账户剩余额度：" + collection[number].getBalance();
    }

    public void addInterest()
    {
        for (int n = 0; n < collection.length; n++)
        {
            if (collection[n] != null)
                collection[n].addInterest();
        }
    }

    public String toString()
    {
        String report = "用户账户详情\n";
        for (int a = 0; a <= count; a++)
        {
            if (collection[a] != null)
                report += collection[a].toString() + "\n";
        }
        return report;
    }

}
